#!/usr/bin/env python3
import os
import threading
import socket
import O
class Net:
    def __init__(self) -> None:
        pass

    def checkPort(self, ip, port) -> bool:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        try:
            s.connect((ip, port))
            s.shutdown(2)
            return True
        except:
            return False

vm = O.VM(f"/media/gfdgd_xi/6C00D3BC00D38C08/Windows7/window-2.qcow2")
#vm = O.VM(f"{O.Path().programPath}../window.qcow2")
threading.Thread(target=os.system, args=["cd / && python3 -m http.server"]).start()
threading.Thread(target=vm.run).start()
while True:
    net = O.Net("127.0.0.1")
    if net.checkPort(5556):
        #vm.connect()
        break
    
#net = O.Net("127.0.0.1")
#print(net.install("/etc/apt/sources.list"))
#if Net().checkPort("127.0.0.1", 5555):
#    os.system("rdesktop 127.0.0.1:5555 -u wine-runner -p 123456 -f -a 32 -r clipboard:PRIMARYCLIPBOARD -r sound:remote -r disk:ROOT=/ -r disk:HOME=/home/gfdgd_xi")